package edu.ccut.saturn.studio.core.util.eclipse;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
import org.eclipse.ui.plugin.AbstractUIPlugin;

public abstract class SaturnDialogUtil {
	private static Map<String, SaturnDialogSettings> dialogSettingMap = new HashMap<String, SaturnDialogSettings>();

	public static boolean openConfirm(Shell shell, String title, String message) {
		return MessageDialog.openConfirm(shell, title, message);
	}
	
	public static void openInformation(Shell shell, String message) {
		MessageDialog.openInformation(shell, Messages.getString("SaturnDialogUtil.remend"), message);  //$NON-NLS-1$
	}

	public static void openError(Shell shell, String message) {
		MessageDialog.openError(shell,
				Messages.getString("SaturnDialogUtil.error"), message); //$NON-NLS-1$
	}

	public static ElementListSelectionDialog createElementListSelectionDialog(
			Shell shape, ILabelProvider provider) {
		
		return new ElementListSelectionDialog(shape, provider);
	}

	public static ElementListSelectionDialog createElementListSelectionDialog(
			ILabelProvider provider) {
		return new ElementListSelectionDialog(Display.getDefault()
				.getActiveShell(), provider);
	}
	
	public static ProgressMonitorDialog createProgressMonitorDialog(Shell shell) {
		return new ProgressMonitorDialog(shell);
	}

	public static FileDialog createFileDialog(String title, String[] filterStr) {
		Shell shell = Display.getDefault().getActiveShell();
		FileDialog filedialog = new FileDialog(shell, 4098);

		filedialog.setText(title);
		filedialog.setFilterExtensions(filterStr);

		return filedialog;
	}

	public static SaturnDialogSettings getSaturnDialogSettings(
			AbstractUIPlugin activator) {
		String key = activator.getBundle().getSymbolicName();

		SaturnDialogSettings dialogSettings = null;

		if (dialogSettingMap.containsKey(key)) {
			dialogSettings = dialogSettingMap.get(key);
		} else {
			dialogSettings = new SaturnDialogSettings(activator);
			dialogSettingMap.put(key, dialogSettings);
		}

		return dialogSettings;
	}
}
